<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('销售出库列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>单据编号：</label>
                                <input type="text" name="chukuDanhao"/>
                            </li>
                            <li>
                                <label>销售日期：</label>
                                <input type="text" class="time-input" placeholder="请选择销售日期" name="chukuDate"/>
                            </li>
                            <li>
                                <label>销售金额：</label>
                                <input type="text" name="jiner"/>
                            </li>
                            <li>
                                <label>付款方式：</label>
                                <select name="paymentMethod" th:with="type=${@dict.getType('sys_pay')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>客户名：</label>
                                <input type="text" name="chukuJingshouren"/>
                            </li>
                            <li>
                                <label>仓库：</label>
                                <select name="chukuCangku"
                                        th:with="type=${@cangkuServiceImpl.selectCangkuAll()}" required>
                                    <option value=""></option>
                                    <option th:each="lists : ${type}"
                                            th:if="${lists.getCangkuName().equals(session.name4user)
                                        || session.QuanXian=='1'||session.QuanXian==1}"
                                            th:text="${lists.getCangkuName()}"
                                            th:value="${lists.getCangkuName()}"
                                    ></option>
                                    <!--                                <option th:each="lists : ${type}" th:text="${lists.getCangkuName()}"-->
                                    <!--                                th:value="${lists.getCangkuName()}"></option>-->
                                    <!--                                <option value=""></option>-->
                                    <!--                                <option th:text="${session.name4user}"></option>-->
                                    <!--                                <option value=""></option>-->
                                    <!--                                <option th:each="lists : ${type}"-->
                                    <!--                                        th:if="${lists.getCangkuName().equals(session.name4user) ||session.QuanXian=='1'}"-->
                                    <!--                                        th:text="${session.QuanXian}"></option>-->
                                </select>
                            </li>
                            <li>
                                <label>商品编号：</label>
<!--                                <input type="text" name="goodId"/>-->
                                <input name="goodId" id="goodId" type="text" class="form-control" list="datalist1">
                                <datalist id="datalist1" th:with="type=${@shangpinxinxiServiceImpl.selectGoods4LeiBieAndName()}">
                                    <option  th:each="lists : ${type}"
                                             th:text="${lists.getShangpinId()+' | '+lists.getShangpinName()}"
                                             th:value="${lists.getShangpinId()}">
                                    </option>
                                </datalist>
                            </li>
                            <li>
                                <label>商品类别：</label>
                                <select name="shangpinLeibie"
                                        th:with="type=${@shangpinxinxiServiceImpl.selectGoods4LeiBie()}" required>
                                    <option hidden value=""></option>
                                    <option th:each="lists : ${type}"
                                            th:text="${lists.getShangpinLeibie()}"
                                            th:value="${lists.getShangpinLeibie()}"></option>
                                </select>
                            </li>
                            <li>
                                <label>商品名称：</label>
                                <input type="text" name="goodName"/>
                            </li>
                            <li>
                                <label>商品规格：</label>
                                <input type="text" name="goodGuige"/>
                            </li>
                            <li>
                                <label>数量：</label>
                                <input type="text" name="shuliang"/>
                            </li>
                            <li>
                                <label>销售单价：</label>
                                <input type="text" name="chukuDanjia"/>
                            </li>
                            <li th:if="${session.QuanXian=='1'||session.QuanXian==1}">
                                <label>总部底价：</label>
                                <input type="text" name="zongbudijia"/>
                            </li>
<!--                            <li>
                                <label>底价：</label>
                                <input type="text" name="dijia"/>
                            </li>-->
                            <li>
                                <label>备注：</label>
                                <input type="text" name="beizhu"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>

                    </div>
                </form>

            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="xiaoshouchuku:chukuTest:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="xiaoshouchuku:chukuTest:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="xiaoshouchuku:chukuTest:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="xiaoshouchuku:chukuTest:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <div hidden id="session2value" th:text="${session.QuanXian}"></div>
                <a class="btn btn-label">
                    <div id="id2toggle" class="fa fa-toggle-off text-info fa-3x" onclick="inStart()">
                        <i class="fa" style="font-size: 45%;vertical-align:45%;">扫码枪录入</i>
                        <textarea  id="msg2saoma" oninput="check2input()" style="height: 0;width: 0;border: 0;padding: unset"></textarea>
                    </div>
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>

        </div>



         <script  th:inline="javascript">
             function check2input() {
                 var text = document.getElementById("msg2saoma").value
                 console.log(text)
                 if (text.search("\n") !== -1){
                     onAdd()
                 }
             }

             document.onmousemove = mouseMove;
             var oldx = 0,oldy = 0;
             function mouseMove(event) {
                 var e = event || window.event;
                 var scrollx = document.documentElement.scrollLeft || document.body.scrollTop;
                 var scrolly= document.documentElement.scrollTop || document.body.scrollTop;
                 var x = e.pageX || e.clientX + scrollx;
                 var y = e.pageY || e.clientY + scrolly;
                 var input2saoma = document.getElementById("msg2saoma");
                 const _select_ = document.activeElement
                 if ((x !== oldx || y !== oldy)&&(_select_ !== input2saoma &&
                     document.getElementById("id2toggle").className ==="fa fa-toggle-on text-info fa-3x")){
                     document.getElementById("msg2saoma").focus()
                     //console.log(_select_)
                     oldx = x;oldy=y;
                 }
             }

             function inStart() {
                 var id2toggle = document.getElementById("id2toggle").className
                 if (id2toggle === "fa fa-toggle-on text-info fa-3x"){
                     document.getElementById("id2toggle").className= "fa fa-toggle-off text-info fa-3x"
                     document.getElementById("msg2saoma").blur()
                 }else {
                     document.getElementById("id2toggle").className= "fa fa-toggle-on text-info fa-3x"
                     document.getElementById("msg2saoma").focus()
                 }
             }

             function onAdd() {
                 var msgStr = document.getElementById("msg2saoma").value
                 //console.log(msgStr)
                 $.ajax({
                     type:"POST",
                     datatype: "string",
                     url: "/xiaoshouchuku/chukuTest/chukuSaoma",
                     data: {"msg": msgStr},
                     success: function (result) {

                         //console.log(16)
                         if (result.code===0) {

                             $.modal.msgSuccess('成功')
                         }else {
                             $.modal.msgError('录入失败')
                         }
                         console.log("result="+result.code)
                         //console.log(17)
                         //alert("提交成功");
                         //$.modal.msgSuccess('成功')
                         document.getElementById("msg2saoma").value = ""
                         document.getElementById("msg2saoma").focus()
                     },
                     error : function() {

                         alert("录入失败");

                     }
                 });
             }


         </script>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('xiaoshouchuku:chukuTest:edit')}]];
        var removeFlag = [[${@permission.hasPermi('xiaoshouchuku:chukuTest:remove')}]];
        var paymentMethodDatas = [[${@dict.getType('sys_pay')}]];
        var prefix = ctx + "xiaoshouchuku/chukuTest";

        $(function () {
            if (document.getElementById("session2value").innerText !== "1"){
                $(function() {
                    var options = {
                        url: prefix + "/list",
                        createUrl: prefix + "/add",
                        updateUrl: prefix + "/edit/{id}",
                        removeUrl: prefix + "/remove",
                        exportUrl: prefix + "/export",
                        modalName: "销售出库",
                        columns: [{
                            checkbox: true
                        },
                            {
                                field: 'id',
                                title: '编号',
                                visible: false
                            },
                            {
                                field: 'chukuDanhao',
                                title: '单据编号'
                            },
                            {
                                field: 'chukuDate',
                                title: '销售日期'
                            },
                            {
                                field: 'jiner',
                                title: '销售金额'
                            },
                            {
                                field: 'paymentMethod',
                                title: '付款方式',
                                formatter: function(value, row, index) {
                                    return $.table.selectDictLabel(paymentMethodDatas, value);
                                }
                            },
                            {
                                field: 'chukuJingshouren',
                                title: '客户名'
                            },
                            {
                                field: 'chukuCangku',
                                title: '仓库'
                            },
                            {
                                field: 'goodId',
                                title: '商品编号'
                            },
                            {
                                field: 'shangpinLeibie',
                                title: '商品类别'
                            },
                            {
                                field: 'goodName',
                                title: '商品名称'
                            },
                            {
                                field: 'goodGuige',
                                title: '商品规格'
                            },
                            {
                                field: 'shuliang',
                                title: '数量'
                            },
                            {
                                field: 'chukuDanjia',
                                title: '销售单价'
                            },
                            /*{
                                field: 'dijia',
                                title: '底价'
                            }*/
                            {
                                field: 'beizhu',
                                title: '备注'
                            },
                            /*{
                                title: '操作',
                                align: 'center',
                                formatter: function(value, row, index) {
                                    var actions = [];
                                    actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                    actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                                    return actions.join('');
                                }
                            }*/
                            ]
                    };
                    $.table.init(options);
                });
            }else{
                $(function() {
                    var options = {
                        url: prefix + "/list",
                        createUrl: prefix + "/add",
                        updateUrl: prefix + "/edit/{id}",
                        removeUrl: prefix + "/remove",
                        exportUrl: prefix + "/export",
                        modalName: "销售出库",
                        columns: [{
                            checkbox: true
                        },
                            {
                                field: 'id',
                                title: '编号',
                                visible: false
                            },
                            {
                                field: 'chukuDanhao',
                                title: '单据编号'
                            },
                            {
                                field: 'chukuDate',
                                title: '销售日期'
                            },
                            {
                                field: 'jiner',
                                title: '销售金额'
                            },
                            {
                                field: 'paymentMethod',
                                title: '付款方式',
                                formatter: function(value, row, index) {
                                    return $.table.selectDictLabel(paymentMethodDatas, value);
                                }
                            },
                            {
                                field: 'chukuJingshouren',
                                title: '客户名'
                            },
                            {
                                field: 'chukuCangku',
                                title: '仓库'
                            },
                            {
                                field: 'goodId',
                                title: '商品编号'
                            },
                            {
                                field: 'shangpinLeibie',
                                title: '商品类别'
                            },
                            {
                                field: 'goodName',
                                title: '商品名称'
                            },
                            {
                                field: 'goodGuige',
                                title: '商品规格'
                            },
                            {
                                field: 'shuliang',
                                title: '数量'
                            },
                            {
                                field: 'chukuDanjia',
                                title: '销售单价'
                            },
                            {
                                field: 'zongbudijia',
                                title: '总部底价'
                            },
                            /*{
                                field: 'dijia',
                                title: '底价'
                            }*/
                            {
                                field: 'beizhu',
                                title: '备注'
                            },
                            /*{
                                title: '操作',
                                align: 'center',
                                formatter: function(value, row, index) {
                                    var actions = [];
                                    actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                    actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                                    return actions.join('');
                                }
                            }*/
                            ]
                    };
                    $.table.init(options);
                });
            }
        })

    </script>
</body>
</html>